package com.example.lenovo.demo.presenter;

import android.content.Context;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lenovo.demo.model.Model;
import com.example.lenovo.demo.model.databean.UserBean;
import com.example.lenovo.demo.model.idatabean.IModel;
import com.example.lenovo.demo.model.idatabean.OnUserSuccess;
import com.example.lenovo.demo.view.ifgview.IUserActivity;

import org.xutils.image.ImageOptions;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/13.
 */

public class UserAcPresenter  {
    private IUserActivity iUserActivity;
    private IModel iModel;
    private Context context;
    private List<UserBean.DataBean> data_user;
    private TextView tv1,tv2;
    private ImageView iv1,iv2;
    private String id;

    public UserAcPresenter(IUserActivity iUserActivity) {
        this.iUserActivity = iUserActivity;
        this.iModel = new Model();
        this.context = iUserActivity.getUserContext();
        this.tv1 = iUserActivity.getTvOne();
        this.tv2 = iUserActivity.getTvTwo();
        this.iv1 = iUserActivity.getImgOne();
        this.iv2 = iUserActivity.getImgTwo();
        this.data_user = new ArrayList<>();
        this.id = iUserActivity.getID();
        Log.i("161101", "UserAcPresenter: "+id);
    }
    public void initData(){
        iModel.sendUserBean(id, new OnUserSuccess() {
            @Override
            public void UserSuccess(List<UserBean.DataBean> data) {
                Log.i("161101", "UserSuccess: "+data.size());
                data_user.addAll(data);
                tv1.setText(data_user.get(0).getName());
                tv2.setText(data_user.get(0).getFollowings_count()+"关注 | "+data_user.get(0).getFollowers_count()+"粉丝");
                Glide.with(context).load(data_user.get(0).getHeader_photo().getPhoto_url()).into(iv1);
                ImageOptions iob = new ImageOptions.Builder().setCircular(true).build();
                org.xutils.x.image().bind(iv2, data_user.get(0).getPhoto_url(), iob);
            }

            @Override
            public void UserFailed() {

            }
        });
    }
}
